package com.tiantianyuegou.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RatingBar;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.tiantianyuegou.R;
import com.tiantianyuegou.activity.YongHuPingJiaActivity;
import com.tiantianyuegou.http.ApiDefine;
import com.tiantianyuegou.model.GoodsModel;
import com.tiantianyuegou.model.PingjiaModel;
import com.tiantianyuegou.util.Content;
import com.tiantianyuegou.view.CircleImageView;

import java.util.ArrayList;
import java.util.List;

/**
 * 用户评价适配器
 * Created by George on 2016/9/6.
 */
public class MyAdapterYonghu extends BaseAdapter {
    private  Context context;
    private  List<PingjiaModel> list;

    //    将数据源通过构造函数进行传递，
    public MyAdapterYonghu(Context context,List<PingjiaModel> list){
        this.context = context;
        this.list = list;
    }
    public MyAdapterYonghu(Context context){
        this.context = context;
        list = new ArrayList<>();
    }
    public void setData(List<PingjiaModel> list){
        this.list.clear();
        this.list.addAll(list);
    }
    @Override
    public int getCount() {
       System.out.println("传递的集合的长度是"+this.list.size());
        return this.list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        PingjiaModel model = list.get(position);
        ViewHolder vh;
        if (convertView == null){
            convertView = View.inflate(context, R.layout.item_listview_yonghupingjia,null);
            vh = new ViewHolder();
            vh.iv_user = (CircleImageView) convertView.findViewById(R.id.iv_user);
            vh.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
            vh.tv_yonghupingjia = (TextView) convertView.findViewById(R.id.tv_yonghupingjia);
            vh.tv_color = (TextView) convertView.findViewById(R.id.tv_color);
            vh.rb = (RatingBar)convertView.findViewById(R.id.rb);
            vh.tv_color_value = (TextView) convertView.findViewById(R.id.tv_color_value);
            vh.tv_size_value = (TextView) convertView.findViewById(R.id.tv_size_value);
            convertView.setTag(vh);
        }
        vh = (ViewHolder) convertView.getTag();
//        ImageLoader.getInstance().displayImage(ApiDefine.SERVER_URL+model.user,vh.iv_user);
      vh.tv_yonghupingjia.setText(model.content);
        vh.tv_color_value.setText(model.color);
        vh.tv_size_value.setText(model.size);
        vh.rb.setRating(Float.parseFloat(model.star));
        
        return convertView;
    }
    class ViewHolder{
        CircleImageView iv_user;
        TextView tv_name,tv_time,tv_yonghupingjia,tv_color,tv_color_value,tv_size_value;
        public RatingBar rb;
    }
}
